
#ifndef _TTG_PIPELINE_CONTEXTED_NODE_
#define _TTG_PIPELINE_CONTEXTED_NODE_
#include "Common/Definitions.h"

#include "DataStreamNode.h"

namespace ttg
{
	namespace pipeline
	{
		//Verison of node, that allows to use diffrent contexts.
		template <class InType, class OutType>
		class ContextedNode :public ttg_internal::pipeline::DataStreamNode<InType, OutType,
																		   InType, OutType>
		{
			public:
				inline ContextedNode(const char *name = "__UNNAMED",
							bool is_serial = false)
					:DataStreamNode(name, is_serial)
				{
					onDataReceive() += structures::make_delegate(this, repackData);
				}
				static void repackData(ContextedNode *object, ttg_internal::pipeline::DataSet *data_set)
				{
					//Creating vector with data.
					ttg::structures::UniversalStack &buffer = data_set->getBuffer();
					std::vector<InType> data;
					while (!buffer.isEmpty())
					{
						data.push_back(buffer.pop<InType>());
					}
					//Creating and sending tasks.
					data_set->addTasks(object->createAndRegisterTasks(data, data_set->getContextID()));
				}
		};
	}
}

#endif
